/**
 * Created by ZFL on 2018/2/10.
 */
/**
 * Created by admin on 2016/12/5.
 */
var vm = new Vue({
    el:'#storeInfId',
    data:{
        memebersInf:[],  //店长信息
        staffInf:[],     //店员信息
        shopperInf:[],   //专属导购信息
        storeName:'',       //店铺名字
        storeAddress:'',    //店铺地址
        storeTel:'',        //到店取href电话
        tel:'',             //店铺电话
        logoPath:'',         //店铺logo的path
        deliveryWays:[]       //配送方式
    },
    methods:{
        getImgPath:function (imgPath) {
            //如果没有 http头文件的话  就加上头文件
            if(imgPath != ''){
                if(imgPath.toString().indexOf('http') <= -1){
                    imgPath = $.imgApi()+""+imgPath;
                }
            }else {
                //img没有path
            }
            return imgPath;
        }
    }
});
//加载页面
function PageInit(){
    pageInfo();
    /*打开服务说明*/
    $(".delivery-method .fr").click(function () {
        $(".container").removeClass("back-show animation-slide-left");
        $(".service-note").addClass("back-show animation-slide-right");
    });
}
//加载店铺信息
function pageInfo() {
    $.ajaxHandler({
        model: function () {
            var obj = {};
            if(com_obj.mallStoreId){
                obj.storeId=com_obj.mallStoreId;
            }else{
                obj.storeId=$.getPara("mallStoreId");
            }
            if(com_obj.userId){
                obj.userId=com_obj.userId;
            }else {
                obj.userId=$.getPara("userId");
            }
            return obj;
        },
        visibleTime: 500,
        approve: true,
        api:"yg_baijiaplatform/userBaUser/getH5StoreDetail",
        success: function (result) {
            console.log(result);
            if (result.code == 10000) {
                var data=result.data;
                var images=data.images;
                if(images.length>0){
                    //店铺图片轮播
                    swiper(images);
                }
                var store=data.store;
                var memebers= data.memebers;

                var shopperInf = [];  //店铺 导购员
                var memebersInf = [];  //店铺 店长
                var staffInf = [];   //店铺 店员

                //店铺基本信息
                vm.logoPath = vm.getImgPath(store.logoPath);  //店铺logo的path
                vm.storeName = store.storeName;  //店铺名字
                vm.storeAddress = store.province+""+store.city+""+store.area+""+store.address;   //到店取地址
                vm.storeTel = "tel:"+store.tel;  //到店取href电话
                vm.tel = store.tel;  //到店取电话

                memebers.picture = vm.getImgPath(memebers.picture);  //设置店长的img的path
                memebersInf.push(memebers);     //店长的信息
                if(memebers.isShopper == 1){    //如果是店长是专属导购  就加入导购行列
                    shopperInf.push(memebers);
                }

                //店铺 店员信息
                $.each(memebers.assistant,function (j,rows) {
                    rows.picture = vm.getImgPath(rows.picture);  //设置店员img的path
                    staffInf.push(rows);   //店员信息
                    if(rows.isShopper == 1){   //如果店员是专属导购  就加入导购行列
                        shopperInf.push(rows);
                    }
                });
                vm.memebersInf = memebersInf;  //店长信息
                vm.shopperInf = shopperInf;   //专属导购信息
                vm.staffInf = staffInf;       //店员信息

                //加载地图
                addMarker(store.lon,store.lat);
                $(".distence").text(store.distance);//服务协议及时送距离

                var obj = {};
                vm.deliveryWays = []; //清空
                //配送方式
                if(store.openExpress==1){//是否快递送
                    obj = {};
                    obj.deliveryWay = 3;
                    var priceNoFreight =divideNumber(store.priceNoFreight,100);
                    if(priceNoFreight==9999.99||priceNoFreight=="9999.99"){
                        priceNoFreight = 0;
                    }
                    obj.priceNoFreight = priceNoFreight+"元";
                    vm.deliveryWays.push(obj);
                }
                if(store.openFlashExpress==1){///是否及时送
                    obj = {};
                    obj.deliveryWay = 1;
                    obj.flashExpressBeginTime = store.flashExpressBeginTime.toString().substr(0,5); //及时送开始时间
                    obj.flashExpressEndTime = store.flashExpressEndTime.toString().substr(0,5);     //及时送结束时间
                    obj.distance = store.distance;    //及时送距离
                    vm.deliveryWays.push(obj);
                }
                if(store.openInstall==1){//是否到店取
                    obj = {};
                    obj.deliveryWay = 2;
                    obj.installBeginTime = store.installBeginTime.toString().substr(0,5);  //到店取开始时间
                    obj.installEndTime = store.installEndTime.toString().substr(0,5);      //到店取结束时间
                    vm.deliveryWays.push(obj);
                }
            }else {
                $.toast("加载失败","text");
            }

        }
    });
}

/*关闭服务说明*/
function returnServer() {
    $(".container").addClass("back-show animation-slide-left");
    $(".service-note").removeClass("back-show animation-slide-right");
}
//地图
var map;
function addMarker(Lng, Lat) {
    map = new AMap.Map("map_container", {
        resizeEnable: true,
        center: [Lng, Lat],//地图中心点
        zoom: 13,//地图显示的缩放级别
        dragEnable:false,//地图是否可通过鼠标拖拽平移
        zoomEnable:false//地图是否可缩放

    });
    //添加点标记，并使用自己的icon
    new AMap.Marker({
        map: map,
        position: [Lng, Lat],
        icon: new AMap.Icon({
            size: new AMap.Size(40, 50),  //图标大小
            image: "../images/shop/dianpu_icon.png",
            imageOffset: new AMap.Pixel(0,0)
        })
    });
}

//轮播图
function swiper(data) {
    var html="";
    $.each(data,function (index,item) {
        if(item.imgUrl.toString().indexOf("http")<=-1){
            html+='<div class="swiper-slide"><img src="'+$.imgApi()+""+item.imgUrl+'"></div>';
        }else{
            html+='<div class="swiper-slide"><img src="'+item.imgUrl+'"></div>';
        }
    });
    $(".swiper-wrapper").html(html);
    var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        paginationClickable: true,
        loop: true,
        autoplay: 2000,
        autoplayDisableOnInteraction: false
    });
}